package com.niiwoo.civet.mobile.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.niiwoo.civet.mobile.vo.request.message.JpushMessageRequestVO;
import com.niiwoo.civet.user.dto.request.JpushMessageRequestDTO;
import com.niiwoo.civet.user.service.MessageDubboService;
import com.niiwoo.civet.user.service.UserBasicInfoDubboService;
import com.niiwoo.tripod.web.annotation.AuthIgnore;
import com.niiwoo.tripod.web.vo.Empty;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author: wuke
 * @Description:
 * @Date: Created in 16:54 2017/12/19
 */
@Slf4j
@RestController
@RequestMapping("/message")
@Api(tags = "消息对外接口", description = "/message")
@AuthIgnore
public class MessageController {
    @Reference(version = "1.0.0")
    private MessageDubboService messageDubboService;
    @Reference(version = "1.0.0")
    private UserBasicInfoDubboService userBasicInfoDubboService;

    @ApiOperation(value = "极光推送对外接口(吴科)")
    @PostMapping("/jpushMessage")
    public Empty jpushMessage(@RequestBody @Valid JpushMessageRequestVO requestVO) {
        log.info("MessageController.jpushMessage.requestVO={}", JSON.toJSONString(requestVO));

        JpushMessageRequestDTO jpushMessageRequestDTO = new JpushMessageRequestDTO();
        jpushMessageRequestDTO.setFromUserId(requestVO.getFromUserId());
        jpushMessageRequestDTO.setContent(requestVO.getContent());
        jpushMessageRequestDTO.setTitle(requestVO.getTitle());
        jpushMessageRequestDTO.setToUserIdList(requestVO.getToUserIdList());
        messageDubboService.jpushMessage(jpushMessageRequestDTO);

        log.info("MessageController.jpushMessage end");
        return Empty.getInstance();
    }
}
